package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.CheckIn;
import com.eling.elcms.travel.model.CheckInImplement;
import com.eling.elcms.travel.model.CheckOutSettlement;
import com.eling.elcms.travel.model.view.AdjustGroupView;
import com.eling.elcms.travel.model.view.CheckInView;
import com.eling.elcms.travel.model.view.CheckOutSettlementView;
import com.eling.elcms.travel.model.view.CheckOutView;
import com.eling.elcms.travel.service.ICheckInManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class CheckInController extends BaseFormController {
	@Autowired
	private ICheckInManager checkInManager;

	@RequestMapping("/api/checkin/save")
	@ResponseBody
	public CheckIn save(@ModelAttribute @ModelFilling CheckIn checkIn) {
		return checkInManager.save(checkIn);
	}

	@RequestMapping("/api/checkin/{pkCheckIn}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkCheckIn) {
		checkInManager.remove(pkCheckIn);
		return new Msg("删除成功");
	}

	@RequestMapping("/api/checkin/checkout")
	@ResponseBody
	public CheckIn checkOut(@ModelAttribute CheckOutView checkOutView) {
		return checkInManager.checkOut(checkOutView);
	}

	@RequestMapping("/api/checkin/checkoutsettlementsave")
	@ResponseBody
	public List<CheckOutSettlement> checkOutSettlementSave(@ModelAttribute CheckOutSettlementView view) {
		return checkInManager.checkOutSettlementSave(view.getList(), view.getBalance(), view.getPaymentMethods(),
				view.getDescription(),view.getcImplement());
	}

	@RequestMapping("/api/checkin/query")
	@ResponseBody
	public List<CheckIn> query(@ModelAttribute CheckIn checkIn) {
		return checkInManager.query(checkIn);
	}

	@RequestMapping("/api/checkin/get")
	@ResponseBody
	public CheckIn get(@RequestParam(value = "pkCheckIn") Long pkCheckIn) {
		return checkInManager.get(pkCheckIn);
	}

	@RequestMapping("/api/checkin/search*")
	@ResponseBody
	public List<CheckIn> search(@ModelAttribute SearchCondition sc, @ModelAttribute CheckIn car) {
		sc.setQueryCondition(car);
		return checkInManager.search(sc);
	}

	@RequestMapping("/api/checkin/queryall")
	@ResponseBody
	public List<CheckInView> queryAll(@ModelAttribute CheckIn car) {
		return checkInManager.queryAll(car);
	}

	/**
	 * 查询组团退房确认列表
	 * 
	 * @param cond
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/checkin/querycheckoutconfirm")
	@ResponseBody
	public List<CheckIn> queryCheckOutConfirm(@ModelAttribute CheckIn cond) {
		return checkInManager.queryCheckOutConfirm(cond);
	}

	/**
	 * 入住前调整列表
	 * @param cii
	 * @param pkDestination
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/checkin/queryadjust")
	@ResponseBody
	public List<AdjustGroupView> queryAdjust(@ModelAttribute CheckInImplement cii,
			@RequestParam(name = "destnSerPoint") String destnSerPoint) {
		return checkInManager.queryAdjust(cii, destnSerPoint);
	}

}
